function features = segment2features(I)
DISPALY = 0;
%% aspect_ratio
stats = regionprops(I, 'BoundingBox');
bounding_box = stats.BoundingBox;
width = bounding_box(3);
height = bounding_box(4);
aspect_ratio = width / height;

%% area
stats = regionprops(I, 'Area');
area = stats.Area;

%% compactness
stats = regionprops(I, 'Perimeter', 'Area');
perimeter = stats.Perimeter;
area = stats.Area;
compactness = perimeter^2 / (4*pi*area);

%% convex hull ratio
stats = regionprops(I, 'Area', 'ConvexHull');
area = stats.Area;
convex_hull_area = polyarea(stats.ConvexHull(:, 1), stats.ConvexHull(:, 2));
convex_hull_ratio = area / convex_hull_area;

if DISPALY == 1
    % Display the original image
    figure;
    imshow(I);
    hold on;
    
    % Plot the convex hull
    plot(stats.ConvexHull(:, 1), stats.ConvexHull(:, 2), 'r', 'LineWidth', 2);
    
    % Set image title and labels
    title('Convex Hull Visualization');
    xlabel('X');
    ylabel('Y');
end

%% horizontal projection
horizontalProjection = sum(I, 2);
% horizontalProjection

if DISPALY == 1
    figure;
    bar(horizontalProjection);
    title('Horizontal Projection Histogram');
    xlabel('Row');
    ylabel('Projection Value');
end

%% Zernike Moments

% 计算每一列的白色像素数量
whitePixelCount = sum(I, 1);

% 确定左边界和右边界
leftBoundary = find(whitePixelCount > 0, 1, 'first');
rightBoundary = find(whitePixelCount > 0, 1, 'last');

% 截取白色部分
whiteRegion = I(:, leftBoundary:rightBoundary, :);
size(whiteRegion)
% Select the order and repetitions of Zernike moments
order = 4;       % Order of Zernike moments
repetitions = 4; % Number of repetitions of Zernike moments

% Calculate the Zernike moments of the image
zernikeMoments = Zernikmoment(whiteRegion', order, repetitions);
zernikeMoments = real(zernikeMoments);

% % Display the Zernike moments
% disp('Zernike Moments:');
% disp(zernikeMoments);

%% Hu Moments
threshold = 0.5; % Adjust the threshold value as needed
mask = whiteRegion > threshold; % Create the mask based on the threshold
eta_mat = SI_Moment(whiteRegion,mask);
hu_arr = Hu_Moments(eta_mat);
% hu_arr

if DISPALY == 1
    % 创建一个包含Hu矩索引的标签
    hu_labels = {'Hu1', 'Hu2', 'Hu3', 'Hu4', 'Hu5', 'Hu6', 'Hu7'};
    
    % 创建一个条形图来表示Hu矩的值
    figure;
    bar(hu_arr);
    title('Hu Moments');
    xlabel('Hu Moment');
    ylabel('Value');
    set(gca, 'XTickLabel', hu_labels);
end


% % 创建一组Gabor滤波器
% wavelength = 2.^(0:5) * 3;
% orientation = 0:45:135;
% g = gabor(wavelength, orientation);
% 
% % 对图像应用Gabor滤波器
% gabormag = imgaborfilt(whiteRegion, g);
% 
% % 计算每个滤波器响应的均值和标准差
% gaborFeatures = [mean(gabormag, [1 2]); std(gabormag, 0, [1 2])];
% % gaborFeatures = gaborFeatures(:)';
% 
% 
% % 计算连通区域的属性
% stats = regionprops('table', whiteRegion, 'Area', 'Perimeter', 'Eccentricity');
% 
% % 提取形状特征
% shapeFeatures = [mean(stats.Area); std(stats.Area); mean(stats.Perimeter); std(stats.Perimeter); mean(stats.Eccentricity); std(stats.Eccentricity)];
% shapeFeatures = shapeFeatures(:)';

%% features
% features = [aspect_ratio*10; area/10; convex_hull_ratio/10;compactness; horizontalProjection; zernikeMoments; hu_arr'*5];
% features = [aspect_ratio*10; area/10; convex_hull_ratio/10;compactness;zernikeMoments; hu_arr'*5];
features = [zernikeMoments; hu_arr'*5];

% features